#pragma once

class CMemChunks;
class CMemBlocks;
struct BlockIndx;

class CMemPool
{
public:
    ~CMemPool();

public:
    static CMemPool *GetInstance();
    bool Initialize(const unsigned int nMaxSize, const unsigned int nMaxLevel);
    void Destroy();

    void *Alloc(unsigned int nLength);
    bool Free(void *pExtBlock);

private:
    CMemPool();
    CMemBlocks *GetRightBlocks(unsigned int nLength);
    static void *AllocHeader();
    static bool FreeHeader(void *ptr);

private:
    unsigned int m_nMaxSize;
    unsigned int m_nMaxLevel;
    BlockIndx *m_pBlockIndx;
    CMemChunks *m_pChunks;

    static CMemPool *m_pInstance;
};
